IPAddress AP_LOCAL_IP(192, 168, 10, 1); //手动设置的开启的网络的ip地址
IPAddress AP_GATEWAY(192, 168, 10, 1); //手动设置的网关IP地址
IPAddress AP_SUBNET(255, 255, 255, 0); //手动设置的子网掩码
//web 接口设置

// 启动wifi AP模式
void startApServer( ) {
  WiFi.softAPConfig (AP_LOCAL_IP, AP_GATEWAY, AP_SUBNET);
  WiFi.softAP(AP_SSID);
  String mess = "Access Point[" + String(AP_SSID) + "] Setting IP[192.168.10.1]";
  Serial.println(mess);
  wifiScan();
}

void servletSet() {
  server.on("/", HTTP_GET, settingRoot);
  server.on("/wifi_ssids", HTTP_GET, getssids);
  server.on("/wifi_setting", HTTP_POST, settingAndConnection);
//  server.on("/status", HTTP_GET, getststus) ;
  server.on("/ws", HTTP_GET, settingAndConnection);
  server.onNotFound(notFound);
}

//void getststus(AsyncWebServerRequest * request)
//{
//  Serial.println("get  listssids request ....");
//  request->send(200, "text/json", WIFI_STATUS_STR);
//}


void getssids(AsyncWebServerRequest * request)
{
  Serial.println("get  listssids request ....");

  request->send(200, "text/json", WIFI_SCAN_JSON);
}



void settingAndConnection(AsyncWebServerRequest * request)
{
  Serial.println("get input >>");


  UserConf conf = getUserConf();
  if (request->hasParam("sid")) {
    conf.sid = request->getParam("sid")->value();
  }

  if (request->hasParam("pass")) {
    conf.pass = request->getParam("pass")->value();
  }
  if (request->hasParam("w_key")) {
    conf.wather_key = request->getParam("w_key")->value();
  }
  if (request->hasParam("w_loc")) {
    conf.localation = request->getParam("w_loc")->value();
  }
  setUserConf(conf);
  saveJsonConf( CONF_FILE_NAME);
  String mess = " " + conf.sid + " \n" +       conf.pass + " \n" +  conf.wather_key +
                "\n" +  conf.localation + "\n setting success..";
  request->send(200, "text/html", mess);
}


void settingRoot(AsyncWebServerRequest *request)
{
  request->send(200, "text/html", SETTING_PAGE);
}


void notFound(AsyncWebServerRequest *request) {
  request->send(404, "text/html", "not found");
}
